package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.utils.poi.ExcelUtilJyjc;
import com.ruoyi.system.domain.JyjcImportLbys;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.JyjcImportSebs;
import com.ruoyi.system.service.IJyjcImportSebsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 十二部所导入Controller
 * 
 * @author ruoyi
 * @date 2025-08-14
 */
@RestController
@RequestMapping("/system/JyjcImportSebs")
public class JyjcImportSebsController extends BaseController
{
    @Autowired
    private IJyjcImportSebsService jyjcImportSebsService;

    /**
     * 查询十二部所导入列表
     */
    @Anonymous
    @GetMapping("/list")
    public TableDataInfo list(JyjcImportSebs jyjcImportSebs)
    {
        startPage();
        List<JyjcImportSebs> list = jyjcImportSebsService.selectJyjcImportSebsList(jyjcImportSebs);
        return getDataTable(list);
    }

    /**
     * 导出十二部所导入列表
     */
    @Anonymous
    @Log(title = "十二部所导入", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, JyjcImportSebs jyjcImportSebs)
    {
        List<JyjcImportSebs> list = jyjcImportSebsService.selectJyjcImportSebsList(jyjcImportSebs);
        ExcelUtil<JyjcImportSebs> util = new ExcelUtil<JyjcImportSebs>(JyjcImportSebs.class);
        util.exportExcel(response, list, "十二部所导入数据");
    }

    /**
     * 获取十二部所导入详细信息
     */
    @Anonymous
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(jyjcImportSebsService.selectJyjcImportSebsById(id));
    }

    /**
     * 新增十二部所导入
     */
    @Anonymous
    @Log(title = "十二部所导入", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JyjcImportSebs jyjcImportSebs)
    {
        return toAjax(jyjcImportSebsService.insertJyjcImportSebs(jyjcImportSebs));
    }

    /**
     * 修改十二部所导入
     */
    @Anonymous
    @Log(title = "十二部所导入", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JyjcImportSebs jyjcImportSebs)
    {
        return toAjax(jyjcImportSebsService.updateJyjcImportSebs(jyjcImportSebs));
    }

    /**
     * 删除十二部所导入
     */
    @Anonymous
    @Log(title = "十二部所导入", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(jyjcImportSebsService.deleteJyjcImportSebsByIds(ids));
    }
    @Anonymous
    @Log(title = "收支汇总", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, String yearyf) throws Exception
    {
        ExcelUtilJyjc<JyjcImportSebs> util = new ExcelUtilJyjc<JyjcImportSebs>(JyjcImportSebs.class);
        List<JyjcImportSebs> jyjcImportSebsList = util.importExcel(file.getInputStream(),4);

        String message = jyjcImportSebsService.importJyjcImportSebs(jyjcImportSebsList, yearyf);
        return success(message);
    }
    @Anonymous
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<JyjcImportSebs> util = new ExcelUtil<JyjcImportSebs>(JyjcImportSebs.class);
        util.importTemplateExcel(response, "收支汇总数据");
    }
}
